package controllers

import (
	"fmt"
	"github.com/astaxie/beego"
	m"xmy/models/admin"
)

type MailController struct {
	beego.Controller
}

//返回值 封装为 JSON 格式
func (this *MailController) Rsp(status bool, str string) {
	this.Data["json"] = &map[string]interface{}{"status": status, "info": str}
	this.ServeJSON()
}

func (c *MailController)  MailConfigManage() {
	fmt.Println("进来--邮箱设置--控制器啦！")
	mail:= m.QueryMail()
	fmt.Println("mail................................",mail)
	//获取第一个silence 里面的值
	c.Data["host"] = mail[0]["Host"]
	c.Data["username"] = mail[0]["Username"]
	c.Data["pwd"] = mail[0]["Pwd"]
	c.Data["from"] = mail[0]["From"]
	c.TplName = "system/mailConfig.html"
}


func (c *MailController)  MailConfigManageDetail() {
	fmt.Println("进来--邮箱详情--控制器啦！")
	mail:= m.QueryMail()
	c.Data["json"] = &map[string]interface{}{"rows": &mail}
	c.ServeJSON()
	return
}


func (c *MailController)  MailConfigManageEdit() {
	fmt.Println("进来--邮箱修改--控制器啦！")
	g := m.Mail{}
	if err := c.ParseForm(&g); err != nil {
		c.Rsp(false, err.Error())
		return
	}
	id, err := m.MailEdit(&g)
	if err == nil && id > 0 {
		c.Rsp(true, "Success")
		return
	} else {
		c.Rsp(false, err.Error())
		return
	}
}
